<template>
  <div class="my-tag">
    <input class="input" type="text" placeholder="输入标签"  
    v-if="edit"  v-select ref="myInput" @keyup.enter="hiddenInput" @blur="hiddenInput"  v-model="tag"/>
    <div class="text" v-else @dblclick="showInput" >{{ value }}</div>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: [String, Number],
    },
  },
  data() { 
      return {
        edit: false,
        tag:''
       }
    },
  methods: {
    showInput() { 
      this.edit = true
      // 在显示input框的时候将参数value给到data中的tag
      this.tag=this.value
    },

    hiddenInput() { 
      this.$emit('input',this.tag)
      this.edit = false
    }
  }
}
</script>

<style scoped lang="less">
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>
